JavaScript

A5.u.elementsetScrollTo Method

Syntax

A5.u.element.setScrollTo(element[,settings])

Arguments

elementelementstring

A pointer to a DOM element or the ID of an element.

settingsobject

Scroll setting.

recurseboolean

If a value of true is passed in then the each scroll parent element will also be scrolled into view with the same settings as the initial scroll.

modestring

How the child element should be scrolled to. The default value is "into-view", which will scroll the child element into view with the least amount of scrolling (child element aligned to the nearest edge). A value of "top" will scroll the element so that it is at the top of the scrollable area. A value of "bottom" will scroll the element so that it is at the bottom of the scrollable area.

viewobject

Optional edge scrolling settings for when the target element overflows the scrollable area.

xstring

The horizontal edge to scroll to when the target element is wider then the scrollable area. Values can be "left" (the default), "right" or "nearest". A value of "none" will not scroll the "x" axis if any of the target element is visible.

ystring

The vertical edge to scroll to when the target element is wider then the scrollable area. Values can be "top" (the default), "bottom" or "nearest". A value of "none" will not scroll the "y" axis if any of the target element is visible.

offsetobject

Optional offset for the scrolling.

xnumber

The number of pixels extra to add to the X axis. For example, a value of 10 will mean that the element will be scrolled so that it is 10 pixels away from the edge of the scrollable area.

ynumber

The number of pixels extra to add to the Y axis. For example, a value of 10 will mean that the element will be scrolled so that it is 10 pixels away from the edge of the scrollable area.

fireEventboolean

Set to true to fire the native scroll event once the scrolling has been set. The default is false.

axisstring

What axes to scroll on. Values can be "both", "x" or "y".

animationobject

If the A5 frameworks custom scrolling is being used, whether to preform the scroll with an animation from the current location to the new location.

allowboolean

Set to true to allow the animation. The default is false.

durationnumber

The duration (in milliseconds) the that the animation should take.

Description

Scrolls the scrollable parent of the passed in element to show that element.

Discussion

A5.u.element.setScrollTo can be used to scroll to an element whether the scrollable parent element is using the A5 frameworks custom scrolling (drag scrolling for mobile), or the browser native scrolling.

Example

// assume "id" is the ID of an element inside of multiple scrollable element
A5.u.element.setScroll(id,{
	recurse: true,
	mode: 'top', // scroll element to top
});
// the element should now be at the top of the screen